package com.iob.coin.controller.kgeditor;

import com.iob.coin.bl.kgeditor.KgEditorService;
import com.iob.coin.vo.EditLinkVO;
import com.iob.coin.vo.NodeVO;
import com.iob.coin.vo.ResponseVO;
import com.iob.coin.vo.TypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * @Author: MengYuxin
 * @Date: 2021/3/12 21:45
 */

@RestController
@CrossOrigin
@RequestMapping("/kgeditor")
public class KgEditorController {

    @Autowired
    KgEditorService kgEditorService;

    @PostMapping("/addNode")
    public ResponseVO addNode(@RequestBody NodeVO nodeVO){
        return kgEditorService.addNode(nodeVO);
    }

    @PostMapping("/addLink")
    public ResponseVO addLink(@RequestBody EditLinkVO editLinkVO){
        return kgEditorService.addLink(editLinkVO);
    }

    @PostMapping("/fixNode")
    public ResponseVO fixNode(@RequestBody NodeVO nodeVO){
        return kgEditorService.fixNode(nodeVO);
    }

    @PostMapping("/fixLink")
    public ResponseVO fixLink(@RequestBody EditLinkVO editLinkVO){
        return kgEditorService.fixLink(editLinkVO);
    }

    @PostMapping("/deleteNode")
    public ResponseVO deleteNode(@PathParam("kgID") int kgID,
                                 @PathParam("id") int id){
        return kgEditorService.deleteNode(kgID,id);
    }

    @PostMapping("/deleteLink")
    public ResponseVO deleteLink(@PathParam("kgID") int kgID,
                                 @PathParam("id") String id){
        return kgEditorService.deleteLink(kgID,Integer.parseInt(id));
    }

    @PostMapping("/addType")
    public ResponseVO addType(@RequestBody TypeVO typeVO){
        return kgEditorService.addType(typeVO);
    }

    @PostMapping("/fixType")
    public ResponseVO fixType(@RequestBody TypeVO typeVO){
        return kgEditorService.fixType(typeVO);
    }

    @PostMapping("/deleteType")
    public ResponseVO deleteType(@PathParam("kgID") int kgID,
                                 @PathParam("id") int id){
        return kgEditorService.deleteType(kgID,id);
    }

    @PostMapping("/cancel")
    public ResponseVO cancel(@PathParam("kgID") int kgID){
        //单步撤回，默认为一步
        return kgEditorService.Cancel(kgID,1);
    }

    @PostMapping("/cancelMore")
    public ResponseVO cancelMore(@PathParam("kgID") int kgID,
                                 @PathParam("step") int step){
        //多步撤回
        return kgEditorService.Cancel(kgID, step);
    }

    @PostMapping("/saveLayout")
    public ResponseVO saveLayout(@PathParam("kgID") int kgID,
                                 @RequestBody List<NodeVO>nodeVOS){
       // System.out.println(nodeVOS);
        return kgEditorService.saveLayout(kgID,nodeVOS);

    }

    @PostMapping("/cancelLayout")
    public ResponseVO cancelLayout(@PathParam("kgID") int kgID){
        return kgEditorService.cancelLayout(kgID);
    }

    @PostMapping("/outputFile")
    public void outputFile(HttpServletResponse response, @PathParam("kgID") int kgID) {
        //System.out.println("导出ID为"+kgID+"的图谱");
        kgEditorService.outputFile(response, kgID);
    }




}
